<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../assets/animate/animate.css">
    <style>
        body{
            padding-bottom: 800px;
        }
        .item{
            margin: 10px 0px;
            background-color: #ccc;
        }
    </style>
</head>
<body>
    <div id="app">
        <input type="button" value="add" @click="arr.push( Math.random() )">
        <ul v-if="state">
            <!-- appear-active-class 第一次页面加载时，对已经存在的元素或组件执行一次进入动画 -->
            <transition-group appear
                appear-active-class="animate__animated animate__fadeInRight"
                enter-active-class="animate__animated animate__fadeInRight"
                leave-active-class="animate__animated animate__fadeOutLeft"
                @after-leave=" flag=false "
            >
                <li class="item" v-for="(item,i) in arr" :key="item">
                    {{ item }}
                    <input type="button" value="x" @click=" removeItem(i) ">
                </li>
            </transition-group>
        </ul>
    </div>
    <script type="module"> 
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        createApp({
            data(){
                return {
                    // arr:[
                    //     Math.random(),
                    //     Math.random(),
                    //     Math.random(),
                    //     Math.random(),
                    //     Math.random()
                    // ]
                    arr:[],
                    flag:false
                }
            },
            computed: {
                state() {
                    return this.arr.length>0||this.flag
                }
            },
            methods: {
                removeItem(i) {
                    if(this.arr.length==1){
                        this.flag = true;
                    }
                    this.arr.splice(i,1)
                }
            },
        }).mount("#app")
    </script>
</body>
</html>